/**
 * 
 */
package com.gragra.sampling.vector;
import java.util.Arrays;
import com.gragra.data.MixingCorpus;
import com.gragra.sampling.assignerFactories.VectorAssignerFactory;
/**
 * @author Christoph Teichmann
 * created Apr 29, 2013 7:55:35 PM
 * @version 0.1
 */
public class LimitedClassesUnitCRPFactory implements VectorAssignerFactory
{
	/**
	 * @param numberOfLabels
	 * @param concentrationParameter
	 */
	public LimitedClassesUnitCRPFactory(int numberOfLabels, double labelConcentration,
			double concentrationParameter, int threads)
	{
		this.numberOfLabels = numberOfLabels;
		this.concentrationParameter = concentrationParameter;
		this.threads = threads;
		this.labelConcentration = labelConcentration;
	}
	
	private final double labelConcentration;
	/**
	 * 
	 */
	private final int threads;
	/**
	 * 
	 */
	private final int numberOfLabels;
	/**
	 * 
	 */
	private final double concentrationParameter;
	/* (non-Javadoc)
	 * @see com.gragra.sampling.assignerFactories.VectorAssignerFactory#createNewInstance(com.gragra.data.MixingCorpus)
	 */
	@Override
	public VectorProbabilityAssigner createNewInstance(
			MixingCorpus<? extends VectorStructure> corpus)
	{
		int getMaxUnit = getMaxUnit(corpus);
		double[] arr = new double[getMaxUnit+1];
		Arrays.fill(arr, concentrationParameter);
		return new LimitedClassesUnitCRP(numberOfLabels, arr, labelConcentration, threads);
	}
	/**
	 *
	 * @param corpus
	 * @return
	 */
	public static int getMaxUnit(MixingCorpus<? extends VectorStructure> corpus)
	{
		int max = -1;
		for(int i=0;i<corpus.size();++i)
		{
			VectorStructure vs = corpus.getEntry(i);
			int[][] codes = vs.getCodes();
			for(int j=0;j<codes.length;++j)
			{max = Math.max(codes[j][0], max);}
		}
		return max;
	}
}